<?php
/**
 * Created by PhpStorm.
 * User: kai.qiu
 * Date: 17/3/5
 * Time: 上午11:09
 */

namespace App\Http\Middleware;

use Closure;
use Hashids\Hashids;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;

class VerifyOrgCode
{
    public function handle($request, Closure $next)
    {

        $orgCode = request()->header('X-org-code', '');

        $hashids = new Hashids('', 10);

        $orgCode = $hashids->decode($orgCode);

        if(empty($orgCode))
        {
            $data['error_code'] = 9998;
            $data['data'] = (object)[];
            $data['error_message'] = '机构信息错误';

            return response()->json($data);
        }

        return $next($request);
    }
}